<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--引入vue-->
    <script src="../js/plugins/vue/dist/vue.js"></script>
    <!--引入axios-->
    <script src="../js/plugins/axios/dist/axios.js"></script>
    <!--axios全局配置-->
    <script src="js/plugins/common.js"></script>
</head>
<body>
    <div id="app">

    </div>
</body>
    <script type="text/javascript">
        new Vue({
            el:'#app',
            data:{},
            methods:{},
            mounted(){
                let url = location.href;
                let jsonObj = parseUrlParams2Obj(url);
                console.log(jsonObj);
                let code = jsonObj.code;
                console.log(code)
                // 发送请求
                this.$http.get("/login/wxLogin/"+code).then(res=>{
                    if (res.data.success){
                        alert("登录成功");
                        //保存token和logininfo对象到localStorage
                        var token = res.data.resultObj.token;
                        var logininfo = res.data.resultObj.logininfo;
                        localStorage.setItem("token",token);
                        //localStorage保存的数据是字符串，所以要将json对象转成json格式的字符串
                        localStorage.setItem("logininfo",JSON.stringify(logininfo));
                        location.href = "/index.html";
                    }else {
                        var access_token = res.data.resultObj.access_token;
                        var openid = res.data.resultObj.openid;
                        location.href = "/binder.html?accessToken="+access_token+"&openId="+openid;
                    }
                }).catch(res=>{
                    alert("系统繁忙，请稍后重试!!!")
                })
            }

        })


    </script>
</html>